package com.bohua.Car.admin.service.Impl;

import com.bohua.Car.admin.common.Lay;
import com.bohua.Car.admin.common.Msg;
import com.bohua.Car.admin.dao.CarlookMapper;
import com.bohua.Car.admin.entity.Carlook;
import com.bohua.Car.admin.entity.Customers;
import com.bohua.Car.admin.service.CarlookService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CarlookServiceImpl implements CarlookService {
    @Resource
    private CarlookMapper carlookMapper;

    @Override
    public Msg addUrl(Carlook carlook) {
        int i=carlookMapper.insert(carlook);
        Msg msg=new Msg();
        if(i>0){
            msg.setMsg("添加成功");
        }else {
            msg.setCode(-1);
            msg.setMsg("添加失败");
        }
        return msg;
    }

    @Override
    public Msg update(Carlook carlook) {
        int i=carlookMapper.updateByPrimaryKeySelective(carlook);
        Msg msg=new Msg();
        if(i>0){
            msg.setMsg("修改成功");
        }else {
            msg.setCode(-1);
            msg.setMsg("修改失败");
        }
        return msg;
    }

    @Override
    public Msg del(Carlook carlook) {
        int i=carlookMapper.deleteByPrimaryKey(carlook.getTpid());
        Msg msg=new Msg();
        if(i>0){
            msg.setMsg("删除成功");
        }else {
            msg.setCode(-1);
            msg.setMsg("删除失败");
        }
        return msg;
    }

    @Override
    public Lay getUrl(Carlook carlook, Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        List<Carlook> url=carlookMapper.getUrl(carlook);
        PageInfo info=new PageInfo(url);
        Lay lay = new Lay();
        lay.setPage(page);
        lay.setCount(info.getTotal());
        lay.setData(info.getList());
        lay.setLimit(limit);
        return lay;
    }
}
